package lt.marsrutai.mobile.android.activity.intent;

import java.util.Arrays;
import java.util.List;

import lt.marsrutai.mobile.android.activity.SchedulesActivity;
import lt.marsrutai.mobile.android.model.Schedule;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Parcelable;

public class SchedulesIntentHolder extends IntentHolder {

    private static final String SCHEDULES = "schedules";
    private static final String SCOPE_FOLDER = "scopeFolder";
    private static final String SCOPE_NAME = "scopeName";

    public SchedulesIntentHolder(Activity sourceActivity) {
        super(sourceActivity, SchedulesActivity.class);
    }

    public SchedulesIntentHolder(Intent intent) {
        super(intent);
    }

    public SchedulesIntentHolder(Bundle bundle) {
        super(bundle);
    }

    public void setScopeFolder(String scopeFolder) {
        intent.putExtra(SCOPE_FOLDER, scopeFolder);
    }

    public String getScopeFolder() {
        return intent.getStringExtra(SCOPE_FOLDER);
    }

    public void setScopeName(String scopeName) {
        intent.putExtra(SCOPE_NAME, scopeName);
    }

    public String getScopeName() {
        return intent.getStringExtra(SCOPE_NAME);
    }

    public void setSchedules(List<Schedule> schedules) {
        intent.putExtra(SCHEDULES, schedules.toArray(new Schedule[0]));
    }
    
    public List<Schedule> getSchedules() {
        Parcelable[] parcelables = intent.getParcelableArrayExtra(SCHEDULES);
        Schedule[] schedules = new Schedule[parcelables.length];
        for (int i = 0; i < schedules.length; i++) {
            schedules[i] = (Schedule) parcelables[i];
        }
        return Arrays.asList(schedules);
    }

}
